<template>
  <div id="sign-in">
    <img
      class="logo"
      src="../../../static/images/signViews/logo.png"
    >
    <div class="content">
      <div class="form-box">
        <div class="form-item" style="margin-bottom: 28px;">
          <label class="form-item__label">账号</label>
          <div class="form-item__content">
            <input type="text" v-model="loginData.username" class="form-item__input">
          </div>
        </div>
        <div class="form-item" style="margin-bottom: 32px;">
          <label class="form-item__label">密码</label>
          <div class="form-item__content">
            <input type="password" v-model="loginData.password" class="form-item__input">
          </div>
        </div>
        <div class="form-item">
          <div class="form-item__content">
            <!--<button class="form-item__btn" style="margin-right: 17px;" @click="goSignUp()">注册</button>-->
            <button class="form-item__btn" @click="signIn(loginData)">登录</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import MYCONF from '../../myconf'
import {mapMutations} from 'vuex'
import eventBus from '../../util/event-bus'
export default {
  name: 'SignIn',

  data() {
    return {
      loginData: {
        username: '',
        password: ''
      }
    }
  },

  methods: {
    ...mapMutations(['setUserInfo']),
    goSignUp() {
      eventBus.$emit('goSignUp', 'up');
    },
    signIn(loginData) {
      /*this.$http.get(MYCONF.USER_INFO_DATA_URL)
        .then(response => {
          response.json().then(json => {
            if (loginData.username == "" || loginData.password == "") {
              console.log('请输入用户名和密码！');
            } else if (loginData.username != json.username || loginData.password != json.password) {
              console.log('用户名或密码不正确！');
            } else {
              this.setUserInfo(json);
              eventBus.$emit('goSignGuide', 'guide');
            }
          });
        }, response => {
          console.error("user info data request error", response.status)
        });*/

      let loginUrl = MYCONF.service.getLoginUrl+loginData.username+'&password='+loginData.password;
      this.$http.get(loginUrl)
        .then(response => {
          response = response.body;
          if(response.status == 200){
            eventBus.$emit('goSignGuide', 'guide');
          }
          if(response.status == 201){
              alert(response.message);
          }
          if(response.status == 202){
            alert(response.message);
          }
        }, response => {
        });

    }
  }
}
</script>

<style lang="scss" scoped>
  @import "../../../static/common/common.scss";

  #sign-in {
    width: 100%;
    height: $min-height;
    background: url("../../../static/images/signViews/sign-in-background.jpg") no-repeat center;
    position: relative;
    .logo {
      position: absolute;
      top: 66px;
      transform: translateX(-50%);
      left: 50%;
    }
    .content {
      width: 728px;
      height: 316px;
      background: linear-gradient(30deg, rgba(5, 32, 53, 0.28), rgba(255, 255, 255, 0.28));
      position: absolute;
      top: 344px;
      left: 50%;
      transform: translateX(-50%);
      .form-box {
        padding-top: 58px;
        padding-left: 126px;
        .form-item {
          .form-item__label {
            width: 84px;
            box-sizing: border-box;
            float: left;
            text-align: left;
            vertical-align: middle;
            font-size: 30px;
            line-height: 56px;
          }
          .form-item__content {
            margin-left: 84px;
            position: relative;
            font-size: 30px;
            line-height: 56px;
            text-align: left;
            .form-item__input {
              box-sizing: border-box;
              height: 56px;
              width: 354px;
              padding: 0 15px;
              line-height: 56px;
              font-size: 30px;
              border: 1px solid #2d465b;
              border-radius: 4px;
              background: rgba(12, 37, 52, 0.8);
              color: #ffffff;
            }
            .form-item__btn {
              background: rgba(35, 74, 136, 0.9);
              border: none;
              border-radius: 4px;
              width: 354px;
              height: 44px;
              line-height: 40px;
              font-size: 24px;
              color: #ffffff;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
</style>
